class Solution
{
public:
    int maxChunksToSorted(vector<int> &arr)
    {
        int preMax = 0;
        int part = 0;
        int n = arr.size();
        for (int i = 0; i < n; ++i)
        {
            preMax = max(preMax, arr[i]);
            if (preMax == i)
            {
                ++part;
            }
        }
        return part;
    }
};